/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.chlitina.store.common.persistence.BaseEntity;
import com.chlitina.store.modules.base.entity.Customer;
import com.chlitina.store.modules.employee.entity.Employee;
import com.chlitina.store.modules.sys.entity.Store;
import com.google.common.collect.Lists;

/**
 * 客户采纳方案Entity
 * @author lvbo
 * @version 2013-06-20
 */
@Entity
@Table(name = "store_customer_solution")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CustomerSolution extends BaseEntity {
	public static final int UNADOPTED_STATUS = -1;//未采纳
	public static final int PROCEED_STATUS = 0;//正在进行
	public static final int END_STATUS = 1;//正常结束
	public static final int STOP_STATUS = 2;//提前终止
	
	private static final long serialVersionUID = 1L;
	private Long id; 		// 客户采纳方案编号
	private Store store; 	// 店面
	private CustomerExam customerExam; 	// 客户诊断
	private SolutionFace solutionFace; // 方案
	private Customer customer; 			// 客户姓名
	private Employee employee;				//诊断员工
	private Date start_date;	// 方案开始日期
	private Date plan_end_date;	// 理论正常结束日期
	private Date real_end_date;	// 方案实际结束日期
	private int status;	// 当前状态	-1 - 未采纳	0 - 正在进行  	1 - 正常结束  	2 - 提前终止
	
	private List<CustomerSolutionAndProduct> productList = Lists.newArrayList();
	private List<CustomerSolutionAndCare> careList = Lists.newArrayList();
	private List<CustomerSolutionMix> mixList = Lists.newArrayList();
	
	public CustomerSolution() {
	}

	public CustomerSolution(Long id){
		this();
		this.id = id;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="STORE_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public Store getStore() {
		return store;
	}

	public void setStore(Store store) {
		this.store = store;
	}
	
	@ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="SCE_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public CustomerExam getCustomerExam() {
		return customerExam;
	}

	public void setCustomerExam(CustomerExam customerExam) {
		this.customerExam = customerExam;
	}

	@ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="SOLUTION_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public SolutionFace getSolutionFace() {
		return solutionFace;
	}

	public void setSolutionFace(SolutionFace solutionFace) {
		this.solutionFace = solutionFace;
	}

    @ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="CUSTOMER_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	@ManyToOne(cascade={CascadeType.REFRESH}, fetch = FetchType.LAZY) 
	@JoinColumn(name="EMPLOYEE_ID")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@NotNull
	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Date getStart_date() {
		return start_date;
	}

	public void setStart_date(Date start_date) {
		this.start_date = start_date;
	}

	public Date getPlan_end_date() {
		return plan_end_date;
	}

	public void setPlan_end_date(Date plan_end_date) {
		this.plan_end_date = plan_end_date;
	}

	public Date getReal_end_date() {
		return real_end_date;
	}

	public void setReal_end_date(Date real_end_date) {
		this.real_end_date = real_end_date;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="customerSolution")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<CustomerSolutionAndProduct> getProductList() {
		return productList;
	}

	public void setProductList(List<CustomerSolutionAndProduct> productList) {
		this.productList = productList;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="customerSolution")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<CustomerSolutionAndCare> getCareList() {
		return careList;
	}

	public void setCareList(List<CustomerSolutionAndCare> careList) {
		this.careList = careList;
	}
	
	@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="customerSolution")
	@NotFound(action = NotFoundAction.IGNORE)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<CustomerSolutionMix> getMixList() {
		return mixList;
	}

	public void setMixList(List<CustomerSolutionMix> mixList) {
		this.mixList = mixList;
	}
}


